/*
@ClassName VerifyParamAop
@Description TODO
@Author SubUp
@Date   2022/8/12
@Version 1.0
*/
package com.sunjob.mrojobschedule.aop;

import com.sunjob.common.domain.scheduleServer.JobSchedule;
import com.sunjob.common.domain.scheduleServer.PlanSchedule;
import com.sunjob.mrojobschedule.util.ScheduleUtils;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;
import java.util.Vector;

@Aspect
@Component
public class VerifyParamAop {
    @Pointcut("@annotation(com.sunjob.common.mroAnno.MethodVerify)")
    public void pointCut(){}

    @Before(value = "pointCut()")
    public void verifyBefore(JoinPoint joinPoint){
        //String类型
        //获取参数值集合
        Object[] args = joinPoint.getArgs();
        //获取参数名集合
        MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
        String[] parameterNames = methodSignature.getParameterNames();
        //校验参数格式
        for (int i = 0;i<parameterNames.length;i++){
            if("staffName".equalsIgnoreCase(parameterNames[i]))
                ScheduleUtils.checkName(args[i].toString());
            if("staffId".equalsIgnoreCase(parameterNames[i]))
                ScheduleUtils.checkCardId(args[i].toString());
            if("examineObjName".equalsIgnoreCase(parameterNames[i])
                    ||"examineObjType".equalsIgnoreCase(parameterNames[i]))
                ScheduleUtils.checkConsequence(args[i].toString());
            if("job".equalsIgnoreCase(parameterNames[i]))
                ScheduleUtils.jobScheduleCheck((JobSchedule) args[i]);
            if("plan".equalsIgnoreCase(parameterNames[i]))
                ScheduleUtils.planScheduleCheck((PlanSchedule) args[i]);
            if("planId".equalsIgnoreCase(parameterNames[i]) || "jobId".equalsIgnoreCase(parameterNames[i])
                || "pageId".equalsIgnoreCase(parameterNames[i]))
                ScheduleUtils.verifyNumber(args[i].toString());
        }
    }
}
